package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.InvestPingLunAuthor;
import com.zzk.lanouhn.myapplication1.modles.InvestPinglunDetailsModle;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 16/9/16.
 */
public class InvestPingLunDetailsAdapter extends RecyclerView.Adapter<InvestPingLunDetailsAdapter.Myholder> {

    private Context context;
    private List<InvestPinglunDetailsModle.DataBean> dataBeanList = new ArrayList<>();

    public InvestPingLunDetailsAdapter(Context context, List<InvestPinglunDetailsModle.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public Myholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_invest_details_pinglun, null);
        Myholder hoder = new Myholder(view);
        return hoder;
    }

    @Override
    public void onBindViewHolder(Myholder holder, final int position) {

        if (dataBeanList.get(position).getTo() == null) {
            holder.ll.setVisibility(View.GONE);
            Picasso.with(context).load(dataBeanList.get(position).getUser_avatar()).into(holder.touxiang);
            holder.name.setText(dataBeanList.get(position).getNickname());
            holder.shijian.setText(dataBeanList.get(position).getCreated());
            holder.zan.setText(dataBeanList.get(position).getGood() + "");
            holder.neirong.setText(dataBeanList.get(position).getContent());
        } else {
            holder.ll.setVisibility(View.VISIBLE);
            Picasso.with(context).load(dataBeanList.get(position).getUser_avatar()).into(holder.touxiang);
            holder.name.setText(dataBeanList.get(position).getNickname());
            holder.shijian.setText(dataBeanList.get(position).getCreated());
            holder.zan.setText(dataBeanList.get(position).getGood() + "");
            holder.neirong.setText(dataBeanList.get(position).getContent());
            holder.ll_name.setText(dataBeanList.get(position).getTo().getNickname());
            holder.ll_neirong.setText(dataBeanList.get(position).getTo().getContent());
        }

        holder.touxiang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, InvestPingLunAuthor.class);
                String zuoZueID = dataBeanList.get(position).getUser_id();
                intent.putExtra("zuozheID", zuoZueID);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    public class Myholder extends RecyclerView.ViewHolder {
        private CircleImageView touxiang;
        private TextView name, shijian, zan, neirong, ll_name, ll_neirong;
        private LinearLayout ll;

        public Myholder(View itemView) {
            super(itemView);
            touxiang = (CircleImageView) itemView.findViewById(R.id.item_invest_pinglun_touxiang);
            name = (TextView) itemView.findViewById(R.id.item_invest_pinglun_name);
            shijian = (TextView) itemView.findViewById(R.id.item_invest_pinglun_shijian);
            zan = (TextView) itemView.findViewById(R.id.item_invest_pinglun_zan);
            neirong = (TextView) itemView.findViewById(R.id.item_invest_pinglun_neirong);
            ll_name = (TextView) itemView.findViewById(R.id.item_invest_pinglun_ll_name);
            ll_neirong = (TextView) itemView.findViewById(R.id.item_invest_pinglun_ll_neirong);
            ll = (LinearLayout) itemView.findViewById(R.id.item_invest_pinglun_ll);

        }
    }

}
